/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.ecommerce.entity.impl;


import br.com.ecommerce.entity.IEntity;
import br.com.ecommerce.validation.ValidPostalCode;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.NotEmpty;

/**
 *
 * @author rpateixeira
 */
@Entity
@Table(name="ENDERECOS")
public class Endereco implements IEntity,Serializable{

    @Id
    @SequenceGenerator(name = "ENDERECO_GENERATOR", sequenceName = "public.enderecoSequence", initialValue = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE,generator="ENDERECO_GENERATOR")
    @Column(name="SEQ_ENDERECO")
    private Long id;
    @NotNull
    @ManyToOne(cascade=CascadeType.PERSIST,optional=false)
    @JoinColumn(name="ID_USUARIO",referencedColumnName="SEQ_USUARIO")
    private Usuario usuario;
    @Column(length=155,nullable=false)
    @NotNull
    @NotEmpty
    private String nickName;
    @NotNull
    @NotEmpty
    @Column(length=255,nullable=false)
    private String endereco;
    @NotNull
    @NotEmpty
    @Column(length=100,nullable=false)
    private String estado;
    @NotNull
    @NotEmpty
    @Column(length=30,nullable=false)
    private String pais;
    @NotNull
    @Min(0)
    @Column(nullable=false)
    private Integer numero;
    @ValidPostalCode
    @NotNull
    @NotEmpty
    @Column(nullable=false)
    private String codigoPostal;
     @OneToMany(cascade=CascadeType.ALL,mappedBy="enderecoToSend")
    private List<Venda> vendas;


    @Override
    public Long getId() {
       return this.id;
    }
    public String getCodigoPostal() {
        return codigoPostal;
    }

    public void setCodigoPostal(String codigoPostal) {
        this.codigoPostal = codigoPostal;
    }
    
    public String getEndereco() {
        return endereco;
    }

    public void setEndereco(String endereco) {
        this.endereco = endereco;
    }

    public String getEstado() {
        return estado;
    }

    public void setEstado(String estado) {
        this.estado = estado;
    }

    
    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }
   
    public Integer getNumero() {
        return numero;
    }

    public void setNumero(Integer numero) {
        this.numero = numero;
    }
    
    public String getPais() {
        return pais;
    }

    public void setPais(String pais) {
        this.pais = pais;
    }
    
    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }
   
    public List<Venda> getVendas() {
        if(vendas==null){
            vendas= new LinkedList<Venda>();
        }
        return vendas;
    }

    public void setVendas(List<Venda> vendas) {
        this.vendas = vendas;
    }


}
